package com.twu.bibilioteca;

import com.sun.tools.corba.se.idl.InvalidArgument;
import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertTrue;

/**
 * Created by IntelliJ IDEA.
 * User: dixithk
 * Date: 6/19/14
 * Time: 11:46 AM
 * To change this template use File | Settings | File Templates.
 */
public class MenuTest {

    UserInterfaceApp ui = new UserInterfaceApp() ;
    Library lib = new Library();

    @Test
    public void ShouldCheckListOfAllBooksOption()
    {

        Menu menu = new Menu();
        List<MenuOperations> options= new ArrayList<MenuOperations>();
        options.add(new ListAllBooks(ui , lib));

        List<String> optionsForDisplay= new ArrayList<String>();
        optionsForDisplay.add("List of Books");

        assertEquals(optionsForDisplay ,menu.setOptions(options));

    }


    @Test
    public void ShouldCheckCheckOutBookOption()
    {
        Menu menu = new Menu();
        List<MenuOperations> options= new ArrayList<MenuOperations>();
        options.add(new CheckOutBook(ui , lib));

        List<String> optionsForDisplay= new ArrayList<String>();
        optionsForDisplay.add("check out a book");

        assertEquals(optionsForDisplay, menu.setOptions(options));

    }


    @Test
    public void ShouldCheckReturnOutBookOption()
    {
        Menu menu = new Menu();
        List<MenuOperations> options= new ArrayList<MenuOperations>();
        options.add(new ReturnBook(ui , lib));

        List<String> optionsForDisplay= new ArrayList<String>();
        optionsForDisplay.add("Return Book");

        assertEquals(optionsForDisplay ,menu.setOptions(options));

    }

    @Test
    public void ShouldCheckQuitOption()
    {
        Menu menu = new Menu();
        List<MenuOperations> options= new ArrayList<MenuOperations>();
        options.add(new MenuOperations() {
            @Override
            public Result action() {
                return new Result("quit" , true);
            }

            @Override
            public String getName() {
                return "quit";  //To change body of implemented methods use File | Settings | File Templates.
            }
        });

        List<String> optionsForDisplay= new ArrayList<String>();
        optionsForDisplay.add("quit");

        System.out.println(menu.setOptions(options));
        assertEquals(optionsForDisplay, menu.setOptions(options));

    }


    @Test
    public void shouldCheckAllOptions()
    {

        Menu menu = new Menu();
        List<MenuOperations> options= new ArrayList<MenuOperations>();
        options.add(new ListAllBooks(ui , lib));
        options.add(new CheckOutBook(ui , lib));
        options.add(new ReturnBook(ui , lib));
        options.add(new MenuOperations() {
            @Override
            public Result action() {
                return new Result("quit" , true);  //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public String getName() {
                return "quit";  //To change body of implemented methods use File | Settings | File Templates.
            }
        });

        List<String> optionsForDisplay= new ArrayList<String>();
        optionsForDisplay.add("List of Books");
        optionsForDisplay.add("check out a book");
        optionsForDisplay.add("Return Book");
        optionsForDisplay.add("quit");
        assertEquals(optionsForDisplay ,menu.setOptions(options));


    }


    @Test
    public void shouldReturnTrueIfSelectedOptionIsBetweenOneAndFour() throws InvalidArgument {
        Menu menu = new Menu();
        assertTrue(menu.isValidOption(1));
        assertTrue(menu.isValidOption(2));
        assertTrue(menu.isValidOption(3));
        assertTrue(menu.isValidOption(4));


    }

    @Test(expected = NumberFormatException.class)
    public void shouldReturnFalseIfSelectedOptionIsNotBetweenOneAndFour() throws InvalidArgument {
        Menu menu = new Menu();
        assertTrue(menu.isValidOption(9));
        assertTrue(menu.isValidOption(10));
    }


}
